package cn.zshprint.serein.controller;

import cn.zshprint.serein.entity.Product;
import cn.zshprint.serein.pojo.ResultBean;
import cn.zshprint.serein.service.EsProductService;
import cn.zshprint.serein.service.ProductService;
import cn.zshprint.serein.vo.ProductVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品控制器
 * (Product)表控制层
 *
 * @author makejava
 * @date 2021/07/28
 * @since 2021-07-28 16:54:57
 */
@RestController
@RequestMapping("product")
public class ProductController {
    /**
     * 产品服务
     */
    @Resource
    private ProductService productService;

    /**
     * 选择一个
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ResultBean<Product> selectOne(Integer id) {
        return new ResultBean<>(productService.selectOne(id));
    }

    /**
     * 选择所有
     *
     * @return {@link ResultBean<List<Product>>}
     */
    @GetMapping("selectAll")
    public ResultBean<List<Product>> selectAll() {
        return new ResultBean<>(productService.selectAll());
    }

    /**
     * 选择所有允许
     *
     * @return {@link ResultBean<List<Product>>}
     */
    @GetMapping("selectAllAllow")
    public ResultBean<List<Product>> selectAllAllow() {
        return new ResultBean<>(productService.selectAllAllow());
    }

    /**
     * 保存
     *
     * @param productVO 产品签证官
     * @return {@link ResultBean<Integer>}
     */
    @PostMapping("save")
    public ResultBean<Integer> save(@RequestBody ProductVO productVO) {
        return new ResultBean<>(productService.save(productVO));
    }

    /**
     * 更新
     *
     * @param product 产品
     * @return {@link ResultBean<Product>}
     */
    @PutMapping("update")
    public ResultBean<Product> update(@RequestBody Product product) {
        return new ResultBean<>(productService.update(product));
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link ResultBean<Integer>}
     */
    @DeleteMapping("delete/{id}")
    public ResultBean<Integer> delete(@PathVariable Integer id) {
        return new ResultBean<>(productService.delete(id));
    }

    @GetMapping("getNoAllow")
    public ResultBean<List<Product>> getNoAllow() {
        return new ResultBean<>(productService.getNoAllow());
    }
}